﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace chessLogic
{
    public class Fen
    {
        private string fenString;

        public string FenString
        {
            get { return this.fenString; }
            set { this.fenString = value; }
        }

        public void CreateFen(Board board, FigureColor whoMove)
        {
            fenString = "";
            for (int i = 7; i >= 0; i--)
            {
                int emptyPosition = 0;
                foreach (char ch in "abcdefgh")
                {
                    Figure figure = board.getFigure(new Position(ch, i));
                    if (figure.Equals(new None()))
                    {
                        emptyPosition++;
                        continue;
                    }
                    if (emptyPosition != 0)
                    {
                        fenString += emptyPosition;
                        emptyPosition = 0;
                    }
                    if (figure.Color == FigureColor.White)
                        fenString += Char.ToUpper(figure.TypeToChar());
                    else
                        fenString += Char.ToLower(figure.TypeToChar());
                }
                if (emptyPosition != 0)
                    fenString += emptyPosition;
                if (i != 0)
                    fenString += "/";
            }
            if (whoMove == FigureColor.White)
                fenString += " w";
            else
                fenString += " b";
        }
    }
}
